﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DisplayWall
{
    public partial class DisplayWallElement : UserControl
    {
        public static new DependencyProperty BackgroundProperty = DependencyProperty.Register("FallBackBackground", typeof(Brush), typeof(DisplayWallElement), new PropertyMetadata(new SolidColorBrush(Colors.Orange), propertyChanged));
        public static DependencyProperty BriefProperty = DependencyProperty.Register("Brief", typeof(string), typeof(DisplayWallElement), new PropertyMetadata("SAMPLE TITLE", propertyChanged));
        public static DependencyProperty TextContentProperty = DependencyProperty.Register("TextContent", typeof(string), typeof(DisplayWallElement), new PropertyMetadata("this is sample text, click to view more.", propertyChanged));
        public static DependencyProperty NavigationDestinationProperty = DependencyProperty.Register("NavigationDestination", typeof(Uri), typeof(DisplayWallElement), new PropertyMetadata(new Uri("http://www.microsoft.com"), propertyChanged));
        public static DependencyProperty TitleAreaBackgroundProperty = DependencyProperty.Register("TitleAreaBackground", typeof(Brush), typeof(DisplayWallElement), new PropertyMetadata(new SolidColorBrush(Colors.Blue), propertyChanged));
        public static DependencyProperty

        static PropertyChangedCallback propertyChanged;

        static DisplayWallElement()
        {
            propertyChanged = (o, property) =>
                {
                    ((DisplayWallElement)o).RefreshProperty();
                };
        }

        public new Brush Background
        {
            get { return (Brush)GetValue(BackgroundProperty); }
            set { SetValue(BackgroundProperty, value); propertyChanged(this, new DependencyPropertyChangedEventArgs()); }
        }

        public string Brief
        {
            get { return (string)GetValue(BriefProperty); }
            set { SetValue(BriefProperty, value); propertyChanged(this, new DependencyPropertyChangedEventArgs()); }
        }

        public string TextContent
        {
            get { return (string)GetValue(TextContentProperty); }
            set { SetValue(TextContentProperty, value); propertyChanged(this, new DependencyPropertyChangedEventArgs()); }

        }

        public Uri NavigationUri
        {
            get { return (Uri)GetValue(NavigationDestinationProperty); }
            set { SetValue(NavigationDestinationProperty, value); propertyChanged(this, new DependencyPropertyChangedEventArgs()); }
        }

        public Brush TitleAreaBackground
        {
            get { return (Brush)GetValue(TitleAreaBackgroundProperty); }
            set { SetValue(TitleAreaBackgroundProperty, value); propertyChanged(this, new DependencyPropertyChangedEventArgs()); }
        }

        public string Data
        {
            get;
            set;
        }

        public DisplayWallElement()
        {
            InitializeComponent();
        }

        void RefreshProperty()
        {
            LayoutRoot.Background = Background;
            Title.Text = Brief;
            Content.Text = TextContent;
            ContentArea.Fill = TitleAreaBackground;
        }

        private void LayoutRoot_MouseEnter(object sender, MouseEventArgs e)
        {
            MouseOverMask.Visibility = System.Windows.Visibility.Visible;
        }

        private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
        {
            MouseOverMask.Visibility = System.Windows.Visibility.Collapsed;

        }
    }
}
